package com.by.controller;

import com.by.bean.Sgoods;
import com.by.bean.querygoods;
import com.by.common.core.bean.PageBean;
import com.by.common.core.bean.ResultBean;
import com.by.common.core.controller.BaseController;
import com.by.remote.system.SgoodsRemote;
import com.by.service.SgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.by.common.core.utils.MapUtils.convertToMap;

@RestController
public class GoodsController extends BaseController implements SgoodsRemote {
    @Autowired
    SgoodsService ss;
    @PostMapping("/savegoods")
    public ResultBean savegoods(@RequestBody Sgoods sgoods){
        int re=ss.saveEntity(sgoods);
        return saveResult(re);
    }
    @GetMapping("/querylist")
    public ResultBean querylist(querygoods qs){
        PageBean list=ss.query(convertToMap(qs.getClass(),qs));
        return success("查询成功",list);
    }
    @Override
    public List querylist(int id) {
        List list=ss.querylistbyid(id);
        return list;
    }
    @PutMapping("/updategoods")
    public ResultBean updategoods(@RequestBody Sgoods sgoods){
        int re=ss.updateEntity(sgoods);
        return updateResult(re);
    }
}
